package com.webflux;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Slf4j
@SpringBootApplication
public class WebFluxApplication {

    public static void main(String[] args) throws UnknownHostException {
        ConfigurableApplicationContext application = SpringApplication.run(WebFluxApplication.class, args);
        Environment env = application.getEnvironment();
        String contextPath = env.getProperty("server.servlet.context-path");
        if (contextPath == null) {
            contextPath = "";
        }
        String agreement = env.getProperty("server.ssl.key-store");
        if (agreement == null) {
            agreement = "http";
        } else {
            agreement = "https";
        }
        log.info("\n---------------------------------------------------------\n" +
                        "Application '{}' is running! Access URLs:\n\t" +
                        "Local: \t\t{}://localhost:{}{}\n\t" +
                        "External: \t{}://{}:{}{}\n\t" +
                        "knife4j Api Doc: \t{}://{}:{}{}/doc.html\n\t" +
                        "WebSocket each:\t ws://{}:{}/each?id=\n" +
                        "\n---------------------------------------------------------\n",
                env.getProperty("spring.application.name"),
                agreement, env.getProperty("server.port"), contextPath,
                agreement, InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                agreement, InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), contextPath,
                InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port")
        );
    }
}
